package com.yang.job.infra.job.configuration;

import com.yang.job.infra.job.YangJobContext;
import com.yang.job.infra.job.YangJobManager;
import com.yang.job.infra.job.thread.YangJobThreadFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Configuration
public class YangJobConfiguration {
    @Bean
    public ScheduledThreadPoolExecutor scheduledThreadPoolExecutor() {
        int availableProcessors = Runtime.getRuntime().availableProcessors();
        return new ScheduledThreadPoolExecutor(availableProcessors, new YangJobThreadFactory("yang"));
    }

    @Bean
    public YangJobManager yangJobManager() {
        return new YangJobManager.YangJobManagerBuilder()
                .setScheduledExecutorService(scheduledThreadPoolExecutor())
                .build();
    }
    @Bean
    public YangJobContext yangJobContext() {
        return new YangJobContext();
    }
}
